package com.whfc.ms.api.emp.controller;

import com.whfc.common.base.BaseController;
import com.whfc.common.result.PageData;
import com.whfc.common.result.Result;
import com.whfc.common.result.ResultUtil;
import com.whfc.common.util.SessionAttr;
import com.whfc.emp.dto.AppTrainingDTO;
import com.whfc.emp.param.AppTrainingAddParam;
import com.whfc.emp.param.AppTrainingEditParam;
import com.whfc.emp.param.AppTrainingListParam;
import com.whfc.fuum.entity.SysUser;
import com.whfc.ms.api.emp.service.MsTrainingService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.AssertFalse;
import java.util.Date;

/**
 * 题库管理-课题
 *
 * @author realm
 * @Description:
 */
@RestController
@RequestMapping("/ms/api/training")
public class AppTrainingController extends BaseController {
    @Autowired
    private MsTrainingService msTrainingService;

    /**
     * 培训考试管理-题库列表
     *
     * @param user
     * @param request
     * @return
     */
    @GetMapping("/list")
    public Result list(@SessionAttribute(SessionAttr.MS_USER) SysUser user, @Validated AppTrainingListParam request) {
        logger.info("培训考试管理-题库列表，loginer:{},AppTrainListParam:{}", user.getUsername(), request.toString());
        PageData<AppTrainingDTO> pageData = msTrainingService.list(request);
        return ResultUtil.success(pageData);
    }

    /**
     * 培训考试管理- 新增题库
     *
     * @param user
     * @param request
     * @return
     */
    @RequiresPermissions("emp/training/add")
    @PostMapping("/add")
    public Result add(@SessionAttribute(SessionAttr.MS_USER) SysUser user, @Validated @RequestBody AppTrainingAddParam request) {
        logger.info("培训考试管理-增加题库，loginer:{},AppTrainingAddParam:{}", user.getUsername(), request.toString());
        msTrainingService.add(request);
        return ResultUtil.success();
    }


    /**
     * 培训考试管理-编辑题库
     *
     * @param user
     * @param request
     * @return
     */
    @RequiresPermissions("emp/training/edit")
    @PostMapping("/edit")
    public Result edit(@SessionAttribute(SessionAttr.MS_USER) SysUser user, @Validated @RequestBody AppTrainingEditParam request) {
        logger.info("培训考试管理-编辑题库，loginer:{},AppTrainEditParam:{}", user.getUsername(), request.toString());
        msTrainingService.edit(request);
        return ResultUtil.success();
    }


    /**
     * 培训考试管理-删除题库
     *
     * @param user
     * @param trainId
     * @return
     */
    @RequiresPermissions("emp/training/del")
    @PostMapping("/del/{trainId}")
    public Result del(@SessionAttribute(SessionAttr.MS_USER) SysUser user, @PathVariable("trainId") Integer trainId) {
        logger.info("培训考试管理-删除题库,loginer:{},trianId:{}", user.getUsername(), trainId);
        msTrainingService.del(trainId);
        return ResultUtil.success();

    }



}
